- name: d8.prometheus.deprecation
  rules:
    - alert: PrometheusServiceMonitorDeprecated
      expr: |
        d8_prometheus_deprecated_servicemonitor == 1
      labels:
        tier: cluster
        severity_level: "8"
      annotations:
        plk_markup_format: markdown
        plk_protocol_version: "1"
        plk_create_group_if_not_exists__d8_prometheus_deprecations: "PrometheusDeprecations,tier=cluster,prometheus=deckhouse,kubernetes=~kubernetes"
        plk_grouped_by__d8_prometheus_deprecations: "PrometheusDeprecations,tier=cluster,prometheus=deckhouse,kubernetes=~kubernetes"
        summary: Deprecated Prometheus ServiceMonitor has found.
        description: |
          Kubernetes cluster uses a more advanced network mechanism - EndpointSlice
          You service monitor `{{ $labels.namespace }}/{{ $labels.name }}` has relabeling with old Endpoint mechanism, starts with `__meta_kubernetes_endpoints_`.
          This relabeling rule support, based on the `_endpoint_` label, will be remove in the future (Deckhouse release 1.60).
          Please, migrate to EndpointSlice relabeling rules. To do this, you have modify ServiceMonitor with changing the following labels:
          ```shell
          __meta_kubernetes_endpoints_name -> __meta_kubernetes_endpointslice_name
          __meta_kubernetes_endpoints_label_XXX -> __meta_kubernetes_endpointslice_label_XXX
          __meta_kubernetes_endpoints_labelpresent_XXX -> __meta_kubernetes_endpointslice_labelpresent_XXX
          __meta_kubernetes_endpoints_annotation_XXX -> __meta_kubernetes_endpointslice_annotation_XXX
          __meta_kubernetes_endpoints_annotationpresent_XXX -> __meta_kubernetes_endpointslice_annotationpresent_XXX
          __meta_kubernetes_endpoint_node_name -> __meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname
          __meta_kubernetes_endpoint_ready -> __meta_kubernetes_endpointslice_endpoint_conditions_ready
          __meta_kubernetes_endpoint_port_name -> __meta_kubernetes_endpointslice_port_name
          __meta_kubernetes_endpoint_port_protocol -> __meta_kubernetes_endpointslice_port_protocol
          __meta_kubernetes_endpoint_address_target_kind -> __meta_kubernetes_endpointslice_address_target_kind
          __meta_kubernetes_endpoint_address_target_name -> __meta_kubernetes_endpointslice_address_target_name
          ```
    - alert: PrometheusScapeConfigDeclarationDeprecated
      expr: count(d8_deprecated_scrape_config) > 0
      labels:
        severity_level: "8"
      annotations:
        plk_markup_format: "markdown"
        plk_protocol_version: "1"
        plk_ignore_labels: "name"
        summary: |-
          AdditionalScrapeConfigs from secrets will be deprecated in soon
        description: |-
          Old way for describing additional scrape config via secrets will be deprecated in prometheus-operator > v0.65.1. Please use CRD ScrapeConfig instead.
          ```https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/proposals/202212-scrape-config.md```

- name: d8.grafana.interval_deprecation
  rules:
    - alert: GrafanaDashboardPanelIntervalDeprecated
      expr: |
        count(d8_grafana_dashboards_deprecated_interval > 0)
      labels:
        tier: cluster
        severity_level: "8"
      annotations:
        plk_markup_format: markdown
        plk_protocol_version: "1"
        plk_create_group_if_not_exists__d8_grafana_deprecations: "GrafanaDeprecations,tier=cluster,kubernetes=~kubernetes"
        plk_grouped_by__d8_grafana_deprecations: "GrafanaDeprecations,tier=cluster,kubernetes=~kubernetes"
        summary: Deprecated Grafana panel intervals have been found.
        description: |
          Before updating to Grafana 10, it's required to rewrite an outdated expressions that uses `$interval_rv`, `interval_sx3` or `interval_sx4` to `$__rate_interval`
          To list all deprecated panel intervals use the expr `sum by (dashboard, panel, interval) (d8_grafana_dashboards_deprecated_interval) > 0`

          Attention: The check runs once per hour, so this alert should go out within an hour after deprecated resources migration.

- name: d8.grafana.alert_rule_deprecation
  rules:
    - alert: GrafanaDashboardAlertRulesDeprecated
      expr: |
        count(d8_grafana_dashboards_deprecated_alert_rule > 0)
      labels:
        tier: cluster
        severity_level: "8"
      annotations:
        plk_markup_format: markdown
        plk_protocol_version: "1"
        plk_create_group_if_not_exists__d8_grafana_deprecations: "GrafanaDeprecations,tier=cluster,kubernetes=~kubernetes"
        plk_grouped_by__d8_grafana_deprecations: "GrafanaDeprecations,tier=cluster,kubernetes=~kubernetes"
        summary: Deprecated Grafana alerts have been found.
        description: |
          Before updating to Grafana 10, it's required to migrate an outdated alerts from Grafana to the external alertmanager (or exporter-alertmanager stack)
          To list all deprecated alert rules use the expr `sum by (dashboard, panel, alert_rule) (d8_grafana_dashboards_deprecated_alert_rule) > 0`

          Attention: The check runs once per hour, so this alert should go out within an hour after deprecated resources migration.

- name: d8.grafana.plugin_deprecation
  rules:
    - alert: GrafanaDashboardPluginsDeprecated
      expr: |
        count(d8_grafana_dashboards_deprecated_plugin > 0)
      labels:
        tier: cluster
        severity_level: "8"
      annotations:
        plk_markup_format: markdown
        plk_protocol_version: "1"
        plk_create_group_if_not_exists__d8_grafana_deprecations: "GrafanaDeprecations,tier=cluster,kubernetes=~kubernetes"
        plk_grouped_by__d8_grafana_deprecations: "GrafanaDeprecations,tier=cluster,kubernetes=~kubernetes"
        summary: Deprecated Grafana plugins have been found.
        description: |
          Before updating to Grafana 10, it's required to check if currently installed plugins will work correctly with Grafana 10
          To list all potentially outdated plugins use the expr `sum by (dashboard, panel, plugin) (d8_grafana_dashboards_deprecated_plugin) > 0`

          Plugin "flant-statusmap-panel" is being deprecated and won't be supported in the near future
          We recommend you to migrate to the State Timeline plugin: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/state-timeline/

          Attention: The check runs once per hour, so this alert should go out within an hour after deprecated resources migration.
